package com.lm.scau.framedemos.Views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lm.scau.framedemos.BaseActivity;
import com.lm.scau.framedemos.R;

/**
 * Function:
 * auth：liming on 2016/5/30 16:37
 * mail：liming@wxchina.com
 */
public class LMTitleBar extends RelativeLayout {

    private TextView backView;
    private TextView titleView;
    private ImageView lineView;
    private BaseActivity mActivity;

    public LMTitleBar(Context context) {
        super(context);
        initView(context);
    }

    public LMTitleBar(final Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        backView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.titlebar,null);
        this.addView(view,new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        backView = ViewHolder.getHolderView(view,R.id.text_view_back);
        titleView = ViewHolder.getHolderView(view,R.id.text_view_title);
        lineView = ViewHolder.getHolderView(view,R.id.line_image_view);
        mActivity = (BaseActivity) context;
    }

    public LMTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void setTitle(String title){
        titleView.setText(title);
    }
    public void hideBackView(){
        backView.setVisibility(View.GONE);
        lineView.setVisibility(View.GONE);
    }
}
